package com.rub.android.ui.activity

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.rub.android.R
import com.rub.android.utils.logI
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.shuyu.gsyvideoplayer.utils.GSYVideoType


class VideoPlayerActivity : AppCompatActivity() {

    private val url = "http://vjs.zencdn.net/v/oceans.mp4"
    private var videoPlayer: StandardGSYVideoPlayer? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video_player)

        initView()


    }

    private fun initView() {
        videoPlayer = findViewById<View>(R.id.gsy_vv) as StandardGSYVideoPlayer
        videoPlayer?.setUp(url, false, "测试视频")

        //增加封面
        val imageView = ImageView(this)
        imageView?.scaleType = ImageView.ScaleType.CENTER_CROP
        imageView.setImageResource(R.mipmap.ic_launcher)
        videoPlayer?.thumbImageView = imageView
        //增加title
        videoPlayer?.titleTextView?.visibility = View.VISIBLE
        //设置返回键
        videoPlayer?.backButton?.visibility = View.VISIBLE
        //是否可以滑动调整
        videoPlayer?.setIsTouchWiget(true)

        // videoPlayer?.currentPlayer?.enlargeImageRes=R.drawable.exo_controls_fullscreen_enter
        //设置返回按键功能
        videoPlayer?.backButton?.setOnClickListener {
            onBackPressed()
        }

        videoPlayer?.startPlayLogic()


        GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL)
        GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL)

        var isFull = videoPlayer?.isIfCurrentIsFullscreen
        videoPlayer?.isIfCurrentIsFullscreen = true
        logI("dddd", "isfull=$isFull")
        //设置全屏按键功能
        videoPlayer!!.fullscreenButton.setOnClickListener {
            //resolveFullBtn()
            if (!isFull!!) {
                videoPlayer?.isIfCurrentIsFullscreen = true
            }
        }
    }

    fun resolveFullBtn() {
        /*if (fullViewContainer == null) {
            return
        }
        if (!isFull) {
            resolveToFull()
        } else {
            resolveMaterialToNormal(gsyVideoPlayer)
        }*/
    }

    /**
     * 处理全屏逻辑
     */
    fun resolveToFull(): Unit {

    }

    override fun onPause() {
        super.onPause()
        videoPlayer!!.onVideoPause()
    }

    override fun onResume() {
        super.onResume()
        videoPlayer!!.onVideoResume()
    }

    override fun onDestroy() {
        super.onDestroy()
        GSYVideoManager.releaseAllVideos()
    }

    override fun onBackPressed() {
        //释放所有
        videoPlayer!!.setVideoAllCallBack(null)
        super.onBackPressed()
    }
}